﻿using System;
using System.IO;

namespace SharpEnviro.Desktop
{
	/// <summary>
	/// Settings for a desktop object.
	/// </summary>
	public class DesktopObjectSettings
	{
		/// <summary>
		/// Create a new instance for the specified path and desktop object type.
		/// </summary>
		/// <param name="path">The path used for creating the settings.</param>
		/// <param name="type">The type of desktop object being created.</param>
		public DesktopObjectSettings(string path, DesktopObjectType type)
		{
			if (type == DesktopObjectType.File && !File.Exists(path))
				throw new FileNotFoundException(String.Format("The file '{0}' could not be found.", path));

			if (type == DesktopObjectType.Directory && !Directory.Exists(path))
				throw new DirectoryNotFoundException(String.Format("The directory '{0}' could not be found.", path));

			_path = path;
			_type = type;
		}

		/// <summary>
		/// The file or directory path for this instance.
		/// </summary>
		public string Path
		{
			get
			{
				return _path;
			}
		}

		/// <summary>
		/// Whether or not the desktop object is a file.
		/// </summary>
		public bool IsFile
		{
			get
			{
				return _type == DesktopObjectType.File;
			}
		}

		/// <summary>
		/// Whether or not the desktop object is a directory.
		/// </summary>
		public bool IsDirectory
		{
			get
			{
				return _type == DesktopObjectType.Directory;
			}
		}

		/// <summary>
		/// Rename the associated file or directory.
		/// </summary>
		/// <param name="newPath">The new file or directory name to be used.</param>
		public void Rename(string newPath)
		{
			if (IsFile)
				_path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(_path), newPath);
			else
				_path = System.IO.Path.GetDirectoryName(newPath);
		}

		private string _path = null;
		private DesktopObjectType _type;
	}
}
